package com.tengjunjie.qianqianaccountbook.qianqianaccountbook.converter;

import com.google.gson.Gson;
import com.tengjunjie.qianqianaccountbook.qianqianaccountbook.entity.UserEntity;
import com.tengjunjie.qianqianaccountbook.qianqianaccountbook.enums.ResultEnum;
import com.tengjunjie.qianqianaccountbook.qianqianaccountbook.exception.AccountBookException;
import com.tengjunjie.qianqianaccountbook.qianqianaccountbook.form.UserForm;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;

/**
 * Created by tengjunjie on 2017/12/3.
 * 用户参数与dto转换类
 */
@Slf4j
public class UserFormToUserDTOConverter {
    public static UserEntity convert(UserForm userForm) {
        Gson gson = new Gson();
        UserEntity userEntity = new UserEntity();
        try {
            userEntity.setName(userForm.getName());
            userEntity.setPhone(userForm.getPhone());
            userEntity.setEmailAddress(userForm.getEmailAddress());
            userEntity.setSex(userForm.getSex());
            userEntity.setImage(userForm.getImage());
            userEntity.setPassWord(userForm.getPassWord());
        } catch (Exception e) {
            log.error("【UserForm对象转换】错误, string={}", userForm.toString());
            throw new AccountBookException(ResultEnum.PARAM_ERROR);
        }
        return userEntity;
    }
}
